package com.example.bootexecutor.web;

import com.example.bootexecutor.task.TestTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CountDownLatch;

@RestController
@Slf4j
public class TestController {

    @Autowired
    private TestTask testTask;


    @RequestMapping("/testTask")
    public String testTask(){
        long start = System.currentTimeMillis();
        CountDownLatch cdl5 = new CountDownLatch(3);
        testTask.doTaskOne(cdl5);
        testTask.doTaskTwo(cdl5);
        testTask.doTaskThree(cdl5);
        log.info("begin wating");
        try {
            cdl5.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("wating");
        long end = System.currentTimeMillis();
        System.out.println("任务全部完成，总耗时：" + (end - start) + "毫秒");
        return "success";
    }
}
